#include <vector>
using namespace std;
class Solution
{
public:
    int peakIndexInMountainArray(vector<int> &arr)
    {
        // 二分 0~答案-1 满足 arr[i]<arr[i+1]
        // 答案 ~ arr.size()-2 满足 arr[i]>arr[i+1]
        int l(0), r(arr.size() - 2);
        while (l < r)
        {
            // 如果向下取整 l必须为mid+1
            int mid = (l + r) >> 1;
            if (arr[mid] <= arr[mid + 1])
                l = mid + 1;
            else
                r = mid;
        }
        return l;
    }
};